package com.hy.mydesktop.client.mvc.core.builder;

import java.util.HashMap;
import java.util.Map;

import com.hy.mydesktop.client.component.type.ComponentControllerEnum;
import com.hy.mydesktop.client.component.type.ComponentTypeEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.ComponentMetaDataConstants;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.MetaDataConstants;

public class ContentPanelBuilderTemplate {

	public static GxtComponentControllerMetaNodeModel createContentPanelTemplate(
			Map<String, Object> map1, Map<String, Object> map2) {
		Map<String , Object> contentPanelController=new HashMap<String, Object>();
		contentPanelController.put("component_controller_model_type", ComponentControllerEnum.CONTENTPANEL_CONTROLLER_MODEL);
		contentPanelController.put("component_controller_model_type_index", ComponentControllerEnum.CONTENTPANEL_CONTROLLER_MODEL.ordinal());
					
		//contentPanelController.put("id", "2_1_contentPanelController_PositonType");				
		//contentPanelController.put("viewdata", "contentPanel_viewData_init_01");
		//contentPanelController.put(MetaDataConstants.GXT_COMPONENT__METANODEMODEL, this.getContentPanelGxtComponentMetaNodeModel());		
				
		GxtComponentControllerMetaNodeModel node2=
			new GxtComponentControllerMetaNodeModel(contentPanelController);
		node2 = ControllerAndComponentMetaNodeModelCreationTemplate.buildCommonAttributes(node2,map1);
		if (map1.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID)!=null) {	
			String controllerMetaModelId=(String)map1.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID);
			String id="contentPanelController_"+controllerMetaModelId;
			node2.setId(id);
			node2.setControllerMetaNodeModelId(id);
		}else {
			throw new RuntimeException("xxxxxxxxxxxxx");
		}
		
		map2.put(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID, node2.getControllerMetaNodeModelId());
		GxtComponentMetaNodeModel gxtComponentMetaNodeModel =getContentPanelGxtComponentMetaNodeModel(map2);
		node2.setGxtComponentMetaNodeModel(gxtComponentMetaNodeModel);

		//node2.setRegisterEventTypes(node2.addGxtAppEventType("0301"));

		return node2;
	}

	

	private static GxtComponentMetaNodeModel getContentPanelGxtComponentMetaNodeModel(
			Map<String, Object> map2 ) {
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("component_model_type", ComponentTypeEnum.CONTENTPANEL_MODEL);
		map.put("component_model_type_index", ComponentTypeEnum.CONTENTPANEL_MODEL.ordinal());
		map.put("headervisible", false);
		//map2.put("heading", "职位类型设置");
		//map.put("id", "02_01_contentPanelGxtComponent_PositonType");	
		//map.put("title", "contentpanel tooltip!");	
		for (String key : map2.keySet()) {
			map.put(key, map2.get(key));
		}
		GxtComponentMetaNodeModel gxtComponentMetaNodeModel=new GxtComponentMetaNodeModel(map);
		//gxtComponentMetaNodeModel.setTitle(map2.get(ComponentMetaDataConstants.TITLE).toString());
		//gxtComponentMetaNodeModel.set(ComponentMetaDataConstants.HEADING, 
		//		map2.get(ComponentMetaDataConstants.HEADING).toString());
		if (map2.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID)!=null) {	
			String controllerMetaModelId=(String)map2.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID);
			String id="contentPanelGxtComponent_"+controllerMetaModelId;
			gxtComponentMetaNodeModel.setId(id);
		}else {
			throw new RuntimeException("xxxxxxxxxxxxx");
		}
		
		gxtComponentMetaNodeModel =ControllerAndComponentMetaNodeModelCreationTemplate.removeUnusedProperties(gxtComponentMetaNodeModel);

		return gxtComponentMetaNodeModel;
	}
	
}
